$(document).ready(function(){
   var communityId=$.getUrlVar('communityId');
      var searchInfo={
          communityId:communityId,
          keyword:""//关键词
      };
      var table=$("#zoneTable");
      var t=table.dataTable({
        "ajax":function(data,callback,setting){
          var page = table.api().page.info();
          $.post("/index.php?m=Assistant&c=Zone&a=search",{
            pageIndex:page.page+1,pageSize:page.length,select:searchInfo.keyword,community_id:searchInfo.communityId},function(data,status){
            console.log(data);
              callback(data); 
          });
        },

        "pageLength":10,
          "ordering":false,
          "deferRender": true,
          "columns":[
          {"data":"id"},
          {"data":"id"},
          {"data":"no"},
          {"data":"name"},
          {"data":"full_parent_name"},//小区地址
          {"data":"id"}
          ],
          "columnDefs":[
          {
            "targets":0,
            "data":"id",
            "render":function(data,type,full,meta){
              return '<input type="checkbox" value="'+data+'" name="zone_id">';
            }
          },
          {
            "targets":5,
            "data":"id",
            "render":function(data,type,full,meta){
              var poStr='<a href="javascript:;" uid="'+data+'" class="label label-success radius zoneBtn">楼盘管理</a><a title="编辑" href="javascript:;" uid="'+data+'" class="ml-5 zoneEdit" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a><a title="删除" href="javascript:;" uid="'+data+'" class="ml-5 zoneDel uid-'+data+'" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
              return poStr;
            }

          }
          ],
        "fnCreatedRow":function(row,data,index){
          //row 表示当前tr，data表示当前行的元素对象，index表示当前tr索引
        },
      "bPaginate": true, //翻页功能
      // "processing": true,
      "searching":false,
      "serverSide": true//服务器模式
        });
$(".searchButton").click(function(){
      searchInfo.keyword=$("#searchName").val();
      t.api().draw();
    });
    // 回车事件
    document.onkeydown = function(e){
                 var ev = document.all ? window.event : e;
                 if(ev.keyCode==13) {
                    e.preventDefault();
                    searchInfo.keyword=$("#searchName").val();
                    t.api().draw();
                 }
            }
});